package hashTable

/*

方法1：hash+位运算(优雅版)
时间复杂度：O(N)
空间复杂度：O(1)
*/
func countPoints(rings string) int {
	bits := map[byte]int{
		'R': 1,
		'G': 2,
		'B': 4,
	}
	var hash [10]int
	for i := 0; i < len(rings); i += 2 {
		hash[rings[i+1]-'0'] |= bits[rings[i]]
	}

	count := 0
	for _, v := range hash {
		if v == 7 {
			count++
		}
	}
	return count
}

/*
方法1：hash+位运算(不优雅版)
时间复杂度：O(N)
空间复杂度：O(1) 最多10个
*/
func countPoints1(rings string) int {
	m := map[byte]int{
		'R': 1,
		'G': 2,
		'B': 4,
	}
	hash := make(map[byte]int)
	for i := 0; i < len(rings); i += 2 {
		pos := rings[i+1]
		hash[pos] = hash[pos] | m[rings[i]]
	}

	count := 0
	for _, v := range hash {
		if v == 7 {
			count++
		}
	}
	return count
}
